<%@page import="entity.PageBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="entity.Student"%>
<%@page import="entity.User"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>student_page_list</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css" />
<style type="text/css">
div form {
	display: inline;
}

nav {
	text-align: center;
}
</style>

</head>
<body>
	<%-- ${list} --%>
	<div style="width: 95%; margin: 0 auto;">
		<table class="layui-hide" id="user_info_manager"
			lay-filter="user_info_manager_filter"></table>
	</div>

	<div style="float: right;">
		<form
			action="${pageContext.request.contextPath}/student?method=search" method="post">
			名字：<input type="text" name="searchName" />
			 <input type="submit" value="搜索" class="btn btn-info" />
		</form>
		<a onclick="insert()" class="btn btn-success">添加</a>
	</div>
	<div style="float: left;">
		欢迎：${user.name} <a href="/ST_JavaEE/loginServlet?method=logout" class="btn btn-info">注销</a> 
			<a href="${pageContext.request.contextPath}/online_user_list.jsp" class="btn btn-primary">在线用户列表</a>
	</div>
	<table
		class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>年龄</td>
			<td>性别</td>
			<td>班级</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<c:forEach items="${pageBean.list}" var="student">
			<tr>
				<td>${student.student_id}</td>
				<td>${student.student_name}</td>
				<td>${student.student_age}</td>
				<td>${student.gender}</td>
				<td>${student.class_id}</td>
				<td><a href="javascript:void(0)" onclick="deleteById(${student.student_id})" class="btn btn-danger">删除</a></td>
				<td><a
					href="<%=request.getContextPath()%>/student?method=toUpdate&student_id=${student.student_id}"
					class="btn btn-warning">修改</a></td>
			</tr>
		</c:forEach>
	</table>
	<nav aria-label="Page navigation">
		<ul class="pagination">
			<%--上一页开始 --%>
			<c:if test="${pageBean.pageNo==1}">
				<li class="disabled">
					<a aria-label="Previous"> 
						<span aria-hidden="true">&laquo;</span>
					</a>
				</li>
			</c:if>
			<c:if test="${pageBean.pageNo!=1}">
				<li><a
					href="<%=request.getContextPath()%>/student?method=pageList&pageNo=${pageBean.pageNo-1}"
					aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
				</a></li>
			</c:if>
			<%--上一页结束--%>
			<c:forEach begin="1" end="${pageBean.totalPage}" var="i">
				<c:if test="${pageBean.pageNo==i}">
					<li class="active"><a href="#">${i}</a></li>
				</c:if>
				<c:if test="${pageBean.pageNo!=i}">
					<li><a
						href="<%=request.getContextPath()%>/student?method=pageList&pageNo=${i}">${i}</a></li>
				</c:if>
			</c:forEach>
			<%--下一页 --%>
			<c:if test="${pageBean.pageNo == pageBean.totalPage}">
				<li class="disabled"><a aria-label="Next"> <span
						aria-hidden="true">&raquo;</span>
				</a></li>
			</c:if>
			<c:if test="${pageBean.pageNo != pageBean.totalPage}">
				<li><a
					href="<%=request.getContextPath()%>/student?method=pageList&pageNo=${pageBean.pageNo+1}"
					aria-label="Previous"> <span aria-hidden="true">&raquo;</span>
				</a></li>
			</c:if>
			<%--下一页结束 --%>
		</ul>
	</nav>
	<script src="static/js/jquery-1.11.3.js" type="text/javascript" charset="UTF-8"></script>
	<script src="static/layer-v3.1.1/layer/layer.js" type="text/javascript"	charset="UTF-8"></script>
	<script src="static/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <script src="static/util.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	//	alert("登陆成功，欢迎！");
		function deleteById(id) {
			/* var isDel = confirm("您确认要删除么？");
			if (isDel) {
				location.href = "/ST_JavaEE/student?method=deleteById&id=" + id;
			} */
			
			layer.confirm(
				"您确认要删除吗？",
				function(index){
					console.log(index);
					$.post(
						"${pageContext.request.contextPath}/student?method=deleteById&id=" + id,
						function(jsonObj){
							if(jsonObj.code == util.SUCCESS){
								mylayer.success(jsonObj.msg);
								location.reload();
							}else{
								mylayer.error(jsonObj.msg);
							}
						},
						"json"
					);
				}
			);
		}
		function insert() {
			layer.open({
				type : 2, // iframe
				title : "添加学生",
				area : ["300px", "200px"],
				content : "${pageContext.request.contextPath}/student?method=getInsertPage"
			});
		}
	</script>

</body>
</html>